package com.itheima.app.controller;

import com.itheima.app.manager.TestSoulManager;
import com.itheima.domain.db.Answers;
import com.itheima.domain.db.SoulPush;
import com.itheima.vo.QuestionnaireVo;
import com.itheima.vo.TestSoulResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author Guanxing
 * @date 2021/9/28
 */
@RestController
public class TestSoulController {

    @Autowired
    private TestSoulManager testSoulManager;

    //测灵魂
    @GetMapping("/testSoul")
    public List<QuestionnaireVo> findTestSoul() throws IOException {
        return testSoulManager.findTestSoul();
    }

    //测灵魂 提交问卷
    @PostMapping("/testSoul")
    public String pushTest(@RequestBody Map<String, List<SoulPush>> answers) throws IOException {

        List<SoulPush> answers1 = answers.get("answers");
        return testSoulManager.pushTest(answers1);
    }

    //测灵魂 查看结果报告的id
    @GetMapping("/testSoul/report/{id}")
    public TestSoulResultVo findReport(@PathVariable("id") String id) throws IOException {

        return testSoulManager.findReport(id);
    }
}
